<?php


use App\Http\Controllers\Cruise\CruiseController;
use App\Http\Controllers\Kms\App\Album\AlbumMainController;
use App\Http\Controllers\Kms\App\Album\AlbumResourceController;
use App\Http\Controllers\Kms\App\App\ClientController;
use App\Http\Controllers\Kms\App\Attendance\AttendanceController;
use App\Http\Controllers\Kms\App\Auth\AuthController;
use App\Http\Controllers\Kms\App\Auth\KmsAuthorizationController;
use App\Http\Controllers\Kms\App\Common\ConfigController;
use App\Http\Controllers\Kms\App\Home\HomeController;
use App\Http\Controllers\Kms\App\Poi\PoiController;
use App\Http\Controllers\Kms\App\System\SystemController;
use App\Http\Controllers\Kms\App\Task\TaskController;
use App\Http\Controllers\Kms\App\User\UserController;
use App\Http\Controllers\Kms\Backend\App\ClientVersionController;
use App\Http\Controllers\Kms\Backend\Feishu\FeishuController;
use App\Http\Controllers\OpenShop\Feishu\CustomerDepartmentController;
use App\Http\Controllers\OpenShop\Feishu\SelectionController;
use App\Http\Controllers\OpenShop\FeishuMini\ConsultantsController;
use App\Http\Controllers\OpenShop\FeishuMini\ShopController;
use App\Http\Controllers\OpenShop\FeishuMini\ProgrammingController;
use App\Http\Controllers\OpenShop\SiteLocation\SiteFormController;
use App\Http\Middleware\OpenShop\FeishuWebAuth;
use App\Http\Middleware\OpenShop\UserPermissionAuth;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Kms\App\SelfCheck\SelfCheckController;

Route::get('demo', function () { return "demo"; });

//获取版本强制更新信息
Route::get('appVersion', [ConfigController::class, 'getAppVersionInfo']);
Route::post('iosCodeUse', [ConfigController::class, 'iosCodeUse']);
Route::get('getIosCode', [ConfigController::class, 'getIosCode']);

Route::prefix("config")->group(function () {
    Route::get("noLogin", [ConfigController::class, "noLogin"]);
});

Route::prefix("auth")->group(function () {
    Route::post("fsLogin", [AuthController::class, "fsLogin"]);
    Route::post("virtualLogin", [AuthController::class, "virtualLogin"]);

    Route::post('token', [AuthController::class, "token"]);
    Route::post("login", [AuthController::class, "login"]);

    Route::middleware(["kmsAuth:kmsApi"])->group(function () {
        Route::get('code', [KmsAuthorizationController::class, "authorize"]);
        Route::post("logout", [AuthController::class, "logout"]);
    });
});


Route::prefix("api")->group(function () {

    Route::middleware(["kmsAuth:kmsApi"])->group(function () {



        /**
         * home
         */
        Route::prefix("home")->group(function () {
            Route::get("regionSelection", [HomeController::class, "regionSelection"]);
            Route::get("activityStore", [HomeController::class, "activityStore"]);
            Route::get("revenueSituation", [HomeController::class, "revenueSituation"]);
            Route::get("baseData", [HomeController::class, "baseData"]);
            Route::get("newlyOpenedStore", [HomeController::class, "newlyOpenedStore"]);
            // 首页 - 门店自检块数据统计
            Route::get("shopSelfCheckGroup", [HomeController::class, "shopSelfCheckGroup"]);
        });

        /**
         * 用户信息
         */
        Route::prefix("user")->group(function () {
            Route::get("userinfo", [UserController::class, "userinfo"]);
        });

        /**
         * 系统信息
         */
        Route::prefix("system")->group(function () {
            Route::get("watermark", [SystemController::class, "watermark"]);
            Route::get("config", [SystemController::class, "config"]);
            Route::get("loginIndexTabAuth", [SystemController::class, "loginIndexTabAuth"]);
        });

        /**
         * 自建应用信息
         */
        Route::prefix("app")->group(function () {
            Route::get("list", [ClientController::class, "list"]);
            Route::get("myList", [ClientController::class, "myList"]);
        });

        /**
         * poi信息
         */
        Route::prefix("poi")->group(function () {
            Route::get("list", [PoiController::class, "list"]);
            Route::get("aMapList", [PoiController::class, "aMapList"]);
        });

        /**
         * 相册主信息
         */
        Route::prefix("albumMain")->group(function () {
            Route::get("/", [AlbumMainController::class, "main"]);
            Route::get("/groupList", [AlbumMainController::class, "groupList"]);
            Route::post("/groupShare", [AlbumMainController::class, "groupShare"]);
        });

        /**
         * 相册资源信息
         */
        Route::prefix("albumResource")->group(function () {
            Route::get("/list", [AlbumResourceController::class, "list"]);
            Route::post("/upload", [AlbumResourceController::class, "upload"]);
            Route::patch("/joinRecycleBin", [AlbumResourceController::class, "joinRecycleBin"]);
            Route::patch("/resetRecycleBin", [AlbumResourceController::class, "resetRecycleBin"]);
            Route::patch("/batchResetRecycleBin", [AlbumResourceController::class, "batchResetRecycleBin"]);//回收站全部还原
            Route::get("/recycleBinList", [AlbumResourceController::class, "recycleBinList"]);
            Route::delete("/del", [AlbumResourceController::class, "del"]);
            Route::delete("/batchDel", [AlbumResourceController::class, "batchDel"]);//回收站全部删除
            Route::post("/encodeUrl", [AlbumResourceController::class, "encodeUrl"]);//连接加密
        });

        Route::prefix("attendance")->group(function () {
            Route::post("/dailyPointTraceUpload", [AttendanceController::class, "dailyPointTraceUpload"]);
            Route::get("/fieldTrace", [AttendanceController::class, "fieldTrace"]);
            Route::post("/punchShare", [AttendanceController::class, "punchShare"]);
            Route::get("/attendanceUserCheck", [AttendanceController::class, "attendanceUserCheck"]);
            Route::get("/attendanceUser", [AttendanceController::class, "attendanceUser"]);
        });

        /**
         * 每日任务管理
         */
        Route::prefix("task")->group(function () {
            Route::get("preShopList", [TaskController::class, "preShopList"]);
            Route::get("shopList", [TaskController::class, "shopList"]);
            Route::post("supervisorList", [TaskController::class, "supervisorList"]);
            Route::post("add", [TaskController::class, "add"])->middleware('customerThrottle:1,10');
            Route::get("detail", [TaskController::class, "detail"]);
            Route::post("approval", [TaskController::class, "approval"]);
            Route::post("submit", [TaskController::class, "submit"])->middleware('customerThrottle:1,5');
            Route::post("invalid", [TaskController::class, "invalid"])->middleware('customerThrottle:1,5');

            // 任务汇总
            Route::prefix("order")->group(function () {
                Route::get("/total", [TaskController::class, "total"]);
                Route::get("/list", [TaskController::class, "list"]);
                Route::get("/staffList", [TaskController::class, "staffList"]);
                Route::get("/branchList", [TaskController::class, "branchList"]);
                Route::post("/setStaffTarget", [TaskController::class, "setStaffTarget"]);
                Route::get("/staffUserList", [TaskController::class, "staffUserList"]);
            });

            // 门店tab
            Route::prefix("shop")->group(function () {
                    Route::get('/sift', [TaskController::class, "shopSift"]);                       // 筛选条件
                    Route::get("/total", [TaskController::class, "shopTotal"]);                     //total
                    Route::get("/list", [TaskController::class, "shopTabList"]);                    //列表
                    Route::get("/windCloud", [TaskController::class, "getWindCloudRank"]);          //门店风云榜
                    // 门店订单详情
                    Route::get('inputs/info', [CruiseController::class, 'inputsInfo']);             // 巡店表单
                    Route::get("/dashboard/cruise", [TaskController::class, "getDashboardCruise"]); //营业指标数据
                    Route::get('/progress', [ShopController::class, 'progress']);                   //流程进度
                    Route::get('/detail', [ShopController::class, 'detail']);                       //门店详情
                    Route::get('/logistics', [ShopController::class, 'logistics']);                 //门店订单详情
                    Route::get('getBusinessData', [CruiseController::class, 'getBusinessData']);    //门店营业数据
                    Route::get('/consultants/lists', [ConsultantsController::class, 'lists']);      //顾问列表
                    Route::post('/consultants/replace', [ConsultantsController::class, 'replace']); //更换顾问
                    Route::get('/manager/list', [SelectionController::class, 'index']);             //开发经理列表
                    // 经营数据 （原增长 门店详情）
                    Route::get('detail/{shopId}', [CruiseController::class, 'shopDetail'])->where('shopId', '[0-9]+');
                    Route::get('order/target', [CruiseController::class, 'shopOrderTarget']);//订货指标
                    // 任务记录
                    Route::get("/processList", [TaskController::class, "processList"]);      //任务记录
                    // 照片素材
                    Route::get("/photoList", [TaskController::class, "photoList"]);          //照片素材
                    // 门店订单
                    Route::get("/orderList", [TaskController::class, "shopOrderList"]);      //年费订单+续签订单列表
                }
            );

            // 选址tab
            Route::prefix("siteLocations")->group(function () {
                    Route::get('/clueClassify', [TaskController::class, 'clueClassify']);                                // 分公司列表
                    Route::get('/sift', [ProgrammingController::class, "sift"]);                                         // 筛选条件
                    Route::get("/list", [ProgrammingController::class, "list"]);                                         // 网规页面列表
                    Route::get("/capacity", [ProgrammingController::class, "capacity"]);                                 // 网规容量渗透率
                    Route::get('/detail', [ProgrammingController::class, "detail"]);                                     // 详情展示
                    Route::get('/site/{id}', [CustomerDepartmentController::class, 'detailSite'])->where('id', '[0-9]+');// 勘址任务详情
                    //获取点位300米内的信息
                    Route::get('dotNearbyInfo', [ProgrammingController::class, "getNearbyDot"]);
                    // 收藏任务
                    Route::post('/collect/{id}', [CustomerDepartmentController::class, 'collectTask'])->where('id', '[0-9]+');
                    Route::get('houseSearchSift', [TaskController::class, 'houseSearchSiftNew']);              //房源搜索筛选项
                    Route::get('houseResourcesList', [TaskController::class, 'houseResourcesList']);           //房源列表
                    Route::get("/siteLocationsSearchSift", [TaskController::class, "siteLocationsSearchSift"]);//落址搜索筛选项
                    Route::get("/siteLocationsTotal", [TaskController::class, "siteLocationsTotal"]);          //落址total
                    Route::get("/siteLocationsList", [TaskController::class, "siteLocationsList"]);            //落址列表
                }
            );
        });

        // 自检
        Route::prefix('self-check')->group(function () {
            // 门店自检 - 门店列表
            Route::get('/shopLists', [SelfCheckController::class, 'shopLists']);
            // 门店自检 - 统计看板
            Route::get('/groupStatusStatistical', [SelfCheckController::class, 'groupStatusStatistical']);
            // 门店自检 -  门店列表
            Route::get('/groupStatusStatisticalShop', [SelfCheckController::class, 'groupStatusStatisticalShop']);
            // 门店自检 - 报告列表
            Route::get('/selfCheckReportLists', [SelfCheckController::class, 'selfCheckReportLists']);
            // 门店自检 - 自检任务基础数据信息
            Route::get('/selfCheckDetail', [SelfCheckController::class, 'selfCheckDetail']);

            // 自检详情/报告
            Route::get('detail/{id}', [SelfCheckController::class, 'detail'])->where('id', '[0-9]+');

            // 自检报告督导审核-保存
            Route::post('auditSave/{id}', [SelfCheckController::class, 'auditSave'])->where('id', '[0-9]+');

            // 自检报告督导审核-提交
            Route::post('auditSubmit/{id}', [SelfCheckController::class, 'auditSubmit'])->where('id', '[0-9]+');
        });
    });

});

Route::prefix("backend")->group(function () {

    Route::middleware([FeishuWebAuth::class, UserPermissionAuth::class])->group(function () {
        /**
         * 飞书
         */
        Route::prefix("fs")->group(function () {
            Route::get("departments", [FeishuController::class, "departments"]);
            Route::get("user", [FeishuController::class, "user"]);
            Route::get("selection", [FeishuController::class, "selection"]);
        });

        /**
         * 自建应用信息
         */
        Route::prefix("app")->group(function () {
            Route::get("list", [\App\Http\Controllers\Kms\Backend\App\ClientController::class, "list"]);
            Route::post("add", [\App\Http\Controllers\Kms\Backend\App\ClientController::class, "add"]);
            Route::patch("update", [\App\Http\Controllers\Kms\Backend\App\ClientController::class, "update"]);
            Route::patch("status", [\App\Http\Controllers\Kms\Backend\App\ClientController::class, "status"]);
            Route::delete("delete", [\App\Http\Controllers\Kms\Backend\App\ClientController::class, "delete"]);
        });

        /**
         * 自建应用信息
         */
        Route::prefix("appVersion")->group(function () {
            Route::get("list", [ClientVersionController::class, "list"]);
            Route::post("add", [ClientVersionController::class, "addVersion"]);
            Route::delete("delete", [ClientVersionController::class, "delete"]);
            Route::patch("update", [ClientVersionController::class, "updateVersion"]);
            Route::post("release", [ClientVersionController::class, "releaseVersion"]);
        });

        /**
         * 考勤
         */
        Route::prefix("attendance")->group(function () {
            Route::post("fieldSwitch",
                [\App\Http\Controllers\Kms\Backend\Attendance\AttendanceController::class, "fieldSwitch"]);
            Route::get("fieldGroupList",
                [\App\Http\Controllers\Kms\Backend\Attendance\AttendanceController::class, "dailyFieldGroupList"]);
//            Route::get("dailyFieldGroupList",
//                [\App\Http\Controllers\Kms\Backend\Attendance\AttendanceController::class, "dailyFieldGroupList"]);
            Route::get("fieldList",
                [\App\Http\Controllers\Kms\Backend\Attendance\AttendanceController::class, "fieldList"]);
            Route::get("fieldTrace",
                [\App\Http\Controllers\Kms\Backend\Attendance\AttendanceController::class, "fieldTrace"]);
            Route::get("fieldTraceDetailList",
                [\App\Http\Controllers\Kms\Backend\Attendance\AttendanceController::class, "fieldTraceDetailList"]);
        });

        /**
         * 相册
         */
        Route::prefix("albumResource")->group(function () {
            Route::get("/lists", [AlbumResourceController::class, "lists"]);
            Route::post("/decodeUrl", [AlbumResourceController::class, "decodeUrl"]);// 链接解密
            Route::post("/batchOperate", [AlbumResourceController::class, "batchOperate"]);//相册批量相关操作
        });
    });

});
